package com.xm.servlet.reception_desk.payment_was_successful;

import com.xm.service.reception_desk.AccountInformationService;
import com.xm.service.reception_desk.OrdersService;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 支付成功
 * @author 康文程
 * @date 2024-1-5
 */
@WebServlet("/payment/was/successful")
public class PaymentWasSuccessfulServlet extends HttpServlet {
    /**
     * 员工信息表Service
     */
    private final AccountInformationService accountInformationService = new AccountInformationService();
    /**
     * 订单Service
     */
    private final OrdersService ordersService = new OrdersService();

    @SneakyThrows(Exception.class)
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String accountId = req.getParameter("accountId");
        String orderId = req.getParameter("orderId");
        String informationId = req.getParameter("informationId");
        req.setAttribute("accountId",accountId);
        ordersService.updateOrderStatusByOrderId(orderId,4);
        req.setAttribute("name",accountInformationService.getNameByInformationId(Integer.parseInt(informationId)));
        req.getRequestDispatcher("/WEB-INF/page/reception_desk/payment_was_successful.jsp").forward(req, resp);
    }
}
